package www.lagou.app;

import org.apache.commons.dbutils.QueryRunner;
import org.apache.commons.dbutils.handlers.ArrayListHandler;
import www.lagou.utils.DruidUtils;

import java.sql.SQLException;
import java.util.Arrays;
import java.util.List;

public class Homework2 {
    public static void main(String[] args) {
        QueryRunner qr = new QueryRunner(DruidUtils.getDataSource());
        String demand1 = "select * from phone where price > 2000 and Year(prodate) < 2019;";
        String demand2 = "select * from phone where color='白色';";
        List<Object[]> phones1 = null;
        List<Object[]> phones2 = null;
        try {
            phones1 = qr.query(demand1, new ArrayListHandler());
            phones2 = qr.query(demand2, new ArrayListHandler());
        } catch (SQLException e) {
            e.printStackTrace();
        }
        System.out.println("查询价格高于2000元，生产日期是2019年之前的所有手机");
        for(Object[] o : phones1){
            System.out.println(Arrays.toString(o));
        }

        System.out.println("查询所有颜色是白色的手机信息 ");
        for(Object[] o : phones2){
            System.out.println(Arrays.toString(o));
        }
    }
}
